4c97d4
@@ -84,7 +84,11 @@
public class MasterAddressTracker extends ZooKeeperNodeTracker {
    */
   public int getMasterInfoPort() {
     try {
-      return parse(this.getData(false)).getInfoPort();
+      final ZooKeeperProtos.Master master = parse(this.getData(false));
+      if (master == null) {
+        return 0;
+      }
+      return master.getInfoPort();
     } catch (DeserializationException e) {
       LOG.warn("Failed parse master zk node data", e);
       return 0;
@@ -92,7 +96,7 @@
public class MasterAddressTracker extends ZooKeeperNodeTracker {
   }
   /**
    * Get the info port of the backup master if it is available.
-   * Return 0 if no current master or zookeeper is unavailable
+   * Return 0 if no backup master or zookeeper is unavailable
    * @param sn server name of backup master
    * @return info port or 0 if timed out or exceptions
    */
@@ -100,7 +104,11 @@
public class MasterAddressTracker extends ZooKeeperNodeTracker {
     String backupZNode = ZKUtil.joinZNode(watcher.backupMasterAddressesZNode, sn.toString());
     try {
       byte[] data = ZKUtil.getData(watcher, backupZNode);
-      return parse(data).getInfoPort();
+      final ZooKeeperProtos.Master backup = parse(data);
+      if (backup == null) {
+        return 0;
+      }
+      return backup.getInfoPort();
     } catch (Exception e) {
       LOG.warn("Failed to get backup master: " + sn + "'s info port.", e);
       return 0;
@@ -142,6 +150,7 @@
public class MasterAddressTracker extends ZooKeeperNodeTracker {
     } catch (InterruptedException e) {
       throw new InterruptedIOException();
     }
+    // TODO javadoc claims we return null in this case. :/
     if (data == null){
       throw new IOException("Can't get master address from ZooKeeper; znode data == null");
     }
@@ -161,6 +170,7 @@
public class MasterAddressTracker extends ZooKeeperNodeTracker {
    * @param zkw ZooKeeperWatcher to use
    * @return master info port in the the master address znode or null if no
    * znode present.
+   * // TODO can't return null for 'int' return type. non-static verison returns 0
    * @throws KeeperException
    * @throws IOException
    */
@@ -172,6 +182,7 @@
public class MasterAddressTracker extends ZooKeeperNodeTracker {
     } catch (InterruptedException e) {
       throw new InterruptedIOException();
     }
+    // TODO javadoc claims we return null in this case. :/
     if (data == null) {
       throw new IOException("Can't get master address from ZooKeeper; znode data == null");
     }
@@ -191,7 +202,7 @@
public class MasterAddressTracker extends ZooKeeperNodeTracker {
    * @param zkw The ZooKeeperWatcher to use.
    * @param znode Where to create the znode; could be at the top level or it
    * could be under backup masters
-   * @param master ServerName of the current master
+   * @param master ServerName of the current master must not be null.
    * @return true if node created, false if not; a watch is set in both cases
    * @throws KeeperException
    */
@@ -210,7 +221,7 @@
public class MasterAddressTracker extends ZooKeeperNodeTracker {
   }
 
   /**
-   * @param sn
+   * @param sn must not be null
    * @return Content of the master znode as a serialized pb with the pb
    * magic as prefix.
    */
@@ -227,11 +238,14 @@
public class MasterAddressTracker extends ZooKeeperNodeTracker {
   }
 
   /**
-   * @param data zookeeper data
-   * @return pb object of master
+   * @param data zookeeper data. may be null
+   * @return pb object of master, null if no active master
    * @throws DeserializationException
    */
   public static ZooKeeperProtos.Master parse(byte[] data) throws DeserializationException {
+    if (data == null) {
+      return null;
+    }
     int prefixLen = ProtobufUtil.lengthOfPBMagic();
     try {
       return ZooKeeperProtos.Master.PARSER.parseFrom(data, prefixLen, data.length - prefixLen);
@@ -241,6 +255,8 @@
public class MasterAddressTracker extends ZooKeeperNodeTracker {
   }
   /**
    * delete the master znode if its content is same as the parameter
+   * @param zkw must not be null
+   * @param content must not be null
    */
   public static boolean deleteIfEquals(ZooKeeperWatcher zkw, final String content) {
     if (content == null){
